{$layout}

{$template "node_menu"}

<h3>节点详情</h3>
<table class="ui table definition selectable">
    <tr>
        <td class="title">节点名称</td>
        <td>{{node.name}}</td>
    </tr>
    <tr>
        <td>状态</td>
        <td><label-on :v-is-on="node.isOn"></label-on></td>
    </tr>
    <tr>
        <td>IP地址</td>
        <td>
            <div v-if="node.ipAddresses.length > 0">
                <div>
                    <div v-for="(address, index) in node.ipAddresses" class="ui label tiny basic">
                        {{address.ip}}
                        <span class="small" v-if="address.name.length > 0">（{{address.name}}<span v-if="!address.canAccess">，不公开访问</span>）</span> &nbsp;
                        <span class="small red" v-if="!address.isOn">[off]</span>
                        <span class="small red" v-if="!address.isUp">[down]</span>
                        <span class="small" v-if="address.name.length == 0 && !address.canAccess">（不公开访问）</span>
                    </div>
                </div>
            </div>
            <div v-else>
                <span class="disabled">暂时还没有填写IP地址。</span>
            </div>
        </td>
    </tr>
    <tr>
        <td colspan="2"><more-options-indicator></more-options-indicator></td>
    </tr>
    <tbody v-show="moreOptionsVisible">
        <tr>
            <td>SSH主机地址</td>
            <td>
                <div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
                    <span v-if="node.login.params.host.length > 0">{{node.login.params.host}}</span>
                    <span v-else class="disabled">尚未设置</span>
                </div>
                <div v-else class="disabled">
                    尚未设置
                </div>
            </td>
        </tr>
        <tr>
            <td>SSH主机端口</td>
            <td>
                <div v-if="node.login != null && node.login.params != null && node.login.params.host != null">
                    <span v-if="node.login.params.port > 0">{{node.login.params.port}}</span>
                    <span v-else class="disabled">尚未设置</span>
                </div>
                <span v-else class="disabled">
                            尚未设置
                        </span>
            </td>
        </tr>
        <tr>
            <td>SSH登录认证</td>
            <td>
                <div v-if="node.login != null && node.login.grant != null && node.login.grant.id > 0">
                    <a :href="'/clusters/grants/grant?grantId=' + node.login.grant.id">{{node.login.grant.name}}<span class="small grey">（{{node.login.grant.methodName}}）</span><span class="small grey" v-if="node.login.grant.username.length > 0">（{{node.login.grant.username}}）</span></a>
                </div>
                <span v-else class="disabled">
                    尚未设置
                </span>
            </td>
        </tr>
        <tr>
            <td>API节点地址</td>
            <td>
                <div v-if="node.apiNodeAddrs != null && node.apiNodeAddrs.length > 0">
                    <span v-for="addr in node.apiNodeAddrs" class="ui label basic small">{{addr}}</span>
                </div>
                <span v-else class="disabled">使用全局设置</span>
            </td>
        </tr>
    </tbody>
</table>
<div class="ui divider"></div>

<h3>运行状态</h3>
<table class="ui table definition selectable">
    <tr>
        <td class="title">运行状态</td>
        <td>
            <div  v-if="node.status.isActive">
                <span class="green">运行中</span> &nbsp;
                <a href="" @click.prevent="stopNode()" v-if="!isStopping"><span>[通过SSH停止]</span></a>
                <span v-if="isStopping">[停止中...]</span>
            </div>
            <div v-else>
                <span class="red">已断开</span> &nbsp;
                <a href="" @click.prevent="startNode()" v-if="node.isInstalled && !isStarting"><span>[通过SSH启动]</span></a>
                <span v-if="node.isInstalled && isStarting">[启动中...]</span>
                <a v-if="!node.isInstalled" :href="'/ns/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + node.id" ><span>去安装&gt;</span></a>
            </div>
        </td>
    </tr>
    <tbody v-show="node.status.isActive">
        <tr>
            <td>CPU用量</td>
            <td>{{node.status.cpuUsageText}} &nbsp; <span v-if="node.status.cpuPhysicalCount > 0" class="small grey">（{{node.status.cpuPhysicalCount}}核心/{{node.status.cpuLogicalCount}}线程）</span></td>
        </tr>
        <tr>
            <td>内存用量</td>
            <td>{{node.status.memUsageText}}</td>
        </tr>
        <tr>
            <td>负载</td>
            <td>{{node.status.load1m}} &nbsp; {{node.status.load5m}} &nbsp; {{node.status.load15m}} &nbsp; <tip-icon content="三个数字分别代表1分钟、5分钟、15分钟平均负载"></tip-icon></td>
        </tr>
    </tbody>
    <tbody>
        <tr v-if="node.status.buildVersion != null && node.status.buildVersion.length > 0">
            <td>版本</td>
            <td>v{{node.status.buildVersion}}
                &nbsp; <a :href="'/ns/clusters/cluster/upgradeRemote?clusterId=' + clusterId" v-if="shouldUpgrade"><span class="red">发现新版本v{{newVersion}} &raquo;</span></a>
            </td>
        </tr>
        <tr v-if="node.status.exePath != null && node.status.exePath.length > 0">
            <td>主程序位置</td>
            <td>{{node.status.exePath}}</td>
        </tr>
        <tr>
            <td>最近API连接状况</td>
            <td>
                <span v-if="node.status.apiSuccessPercent > 0 && node.status.apiAvgCostSeconds > 0">
                    <span v-if="node.status.apiSuccessPercent <= 50" class="red">连接错误异常严重（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                    <span v-else-if="node.status.apiSuccessPercent <= 80" class="red">连接错误较多（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                    <span v-else-if="node.status.apiSuccessPercent < 100" class="orange">有连接错误发生（{{round(100 - node.status.apiSuccessPercent)}}%失败），请改善当前节点和API节点之间通讯</span>
                    <span v-else>
                        <span v-if="node.status.apiAvgCostSeconds <= 1" class="green">连接良好</span>
                        <span v-else-if="node.status.apiAvgCostSeconds <= 5" class="orange">连接基本稳定（平均{{round(node.status.apiAvgCostSeconds)}}秒）</span>
                        <span v-else-if="node.status.apiAvgCostSeconds <= 10" class="orange">连接速度较慢（平均{{round(node.status.apiAvgCostSeconds)}}秒）</span>
                        <span v-else class="red">连接非常慢（平均{{round(node.status.apiAvgCostSeconds)}}秒），请改善当前节点和API节点之间通讯</span>
                    </span>
                </span>
                <span v-else class="disabled">尚未上报数据</span>
            </td>
        </tr>
        <tr v-if="nodeDatetime.length > 0">
            <td>上次更新时间</td>
            <td>
                {{nodeDatetime}}
                <p class="comment" v-if="nodeTimeDiff > 30"><span class="red">当前节点时间与API节点时间相差 {{nodeTimeDiff}} 秒，请同步节点时间。</span></p>
            </td>
        </tr>
    </tbody>
</table>
<p class="comment" v-if="node.status.isActive">每隔30秒钟更新一次运行状态。</p>

<div class="ui divider"></div>
<h3>安装信息</h3>
<table class="ui table definition selectable">
    <tr>
        <td>节点ID<em>（id）</em></td>
        <td>{{node.uniqueId}}</td>
    </tr>
    <tr>
        <td>密钥<em>（secret）</em></td>
        <td>{{node.secret}}</td>
    </tr>
    <tr>
        <td class="title">安装目录</td>
        <td>
            <div v-if="node.installDir.length == 0">使用集群设置<span v-if="node.cluster != null && node.cluster.installDir.length > 0">（{{node.cluster.installDir}}）</span></div>
            <span v-else>{{node.installDir}}</span>
        </td>
    </tr>
    <tr>
        <td>已安装</td>
        <td>
            <span v-if="node.isInstalled" class="green">已安装</span>
            <a v-else :href="'/ns/clusters/cluster/node/install?clusterId=' + clusterId + '&nodeId=' + nodeId" class="underline" title="点击进入安装界面"><span class="red">未安装</span></a>
        </td>
    </tr>
</table>